`ifndef TRANSACTION_SVH
`define TRANSACTION_SVH

virtual class trans_base;
	pure virtual function void copy(input trans_base rhs =null);
	pure virtual function void print(string name = "");
endclass

class trans_a extends trans_base; // Derive trans_a from trans_base
	bit [3:0] a; // New property

	function new(input bit [3:0] a = 0); // has arguments
		this.a = a;
	endfunction

	virtual function void copy(input trans_base rhs = null);
		trans_a rhs_;
		if ((rhs == null) || !$cast(rhs_, rhs))
			$display("copy fail");
		a = rhs_.a; // Copy data fields
	endfunction

	virtual function void print(input string name = "");
		$display("%s: a=%0d", name, a);
	endfunction
endclass

class trans_b extends trans_a; // Derive trans_b from trans_a
	bit [3:0] b; // New property

	function new(input bit [3:0] a = 0, bit [3:0] b = 0);
		super.new(a); // must be first line of new
		this.b = b;
	endfunction

	virtual function void copy(input trans_base rhs = null);
		trans_b rhs_; // Derived class handle
		if ((rhs == null) || !$cast(rhs_, rhs))
			$display("copy fail");
		super.copy(rhs);
		b = rhs_.b; // Copy data fields
	endfunction

	virtual function void print(input string name = "");
		super.print(name);
		$display("%s: b=%0d", name, b);
	endfunction
endclass

`endif
